import Ix from './ix.js';
import Bx from './bx.js';

// 定义路由
const router = new VueRouter({
    mode: 'hash',
    routes: [{
            path: '/', //默认路由重定向至登录页
            redirect: 'login'
        },
        {
            path: '*', //默认路由重定向至登录页
            component: () => import('@/views/404.vue')
        },
        {
            path: "/menus",
            name: "menus",
            component: resolve => require(['@/views/menus'], resolve),
            children: [
                ...Bx
            ],
        },
        ...Ix

    ]
})

//无登录页面
router.beforeEach((to, from, next) => {
    if (to.path === '/role') {
        next();
    } else {
        next();
        // let token = localStorage.getItem('token');

        // if (token === null || token === '') {
        //     next('/role');

        // } else {
        //     next();
        // }
    }
});

// 有登录页
// router.beforeEach((to, from, next) => {
//     if (to.path === '/login') {
//         next();
//     } else {
//         let token = localStorage.getItem('token');

//         if (token === null || token === '') {
//             next('/login');

//         } else {
//             next();
//         }
//     }
// });

// 导出
export default router
